import { Component, OnInit,Input, ComponentFactoryResolver, Injector, ElementRef,
  ComponentRef, AfterViewInit, OnDestroy } from '@angular/core';
import { CustomToastOption } from './custom-toast-provider.service';
import { YupRef, YUP_DATA } from './popup.ref';
@Component({
  selector: 'app-common-toast',
  templateUrl: './common-toast.component.html',
  styleUrls: ['./common-toast.component.scss'],
})

export class CommonToastComponent{

  public data: CustomToastOption = {
    icon:true,
    iconSuccess:true,
    message:'',
    duration:2000
  };

  public dialogRef: YupRef<CommonToastComponent>;

  public active: boolean;

  constructor(private injector: Injector){
      this.data = this.injector.get(YUP_DATA);
      this.dialogRef = this.injector.get(YupRef,this.data);
      this.active = true;
      setTimeout(() => {
        this.active = false;
        this.close();
      },this.data.duration);
  }

  public close() {
    setTimeout(() =>  {
      this.dialogRef.close();
    }, 300);
  }

}
